home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / DataScope 2.0.3 / DataScope2l / DSSource / fdlog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  21.8 KB  |  1,008 lines  |  [TEXT/MPS ]

  1. /*
  2. *  File fdlog.c
  3. *
  4. *  Take care of the dialog actions required for NCSA DataScope.
  5. *
  6. */
  7.  
  8.  
  9. # define aboutMeDLOG    139
  10. # define openDLOG          131
  11. # define attrDLOG          129
  12. # define nomemDLOG      132
  13. # define pattDLOG          133
  14. # define isizeDLOG      135
  15.  
  16. #define okButton         1
  17. #define aboutHELP        2
  18. #define aboutOK            1
  19.  
  20. #include "macfview.h"
  21. #include "DSversion.h"
  22. /*
  23.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24.     OutlineItem        Outline a dialog item
  25.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. */
  27. pascal void OutlineItem( theDialog, theItem)
  28.     DialogPtr    theDialog;
  29.     short        theItem;
  30. {
  31.     Rect        ibox;
  32.     char        **ihndl;
  33.     short        typ;
  34.     
  35.     GetDItem( theDialog, theItem, &typ, &ihndl, &ibox);
  36.     PenSize((short) 3,(short) 3);
  37.     InsetRect( &ibox, (short) -4,(short) -4);
  38.     FrameRoundRect( &ibox, (short) 16,(short) 16);
  39. }
  40.  
  41. /********************************************************************/
  42. /*  checkmem
  43. *   Use CompactMem to see if there is enough memory.  If not, call
  44. *   nomem to inform the user.
  45. */
  46. checkmem(amount)
  47.     int amount;
  48.     {
  49.     char *p;
  50.     
  51.     if (NULL == (p = (char *)NewPtr(amount))) {        /* try to allocate it */
  52.         nomem();
  53.         return(1);
  54.     }
  55.     
  56.     DisposPtr(p);                                /* turn it back */
  57. #ifdef OLDM
  58.     if (amount > CompactMem(amount)) {
  59.         nomem();
  60.         return(1);
  61.     }
  62. #endif
  63.  
  64.     return(0);
  65.     
  66. }
  67.  
  68. /********************************************************************/
  69. /*  nomem
  70. *  Inform the user that there is not enough memory for what they
  71. *  want to do.
  72. */
  73. nomem()
  74. {
  75.  
  76.     StopAlert(1002, nil);
  77.     
  78.     return;
  79. }
  80.  
  81. /********************************************************************/
  82. /*  modal dialog filter for drawing the viewport rectangle.
  83. */
  84.  
  85. #define hoffset 30
  86. #define voffset 55
  87.  
  88. #define pOK 1
  89. #define pCANCEL 15
  90. #define pnorth 2
  91. #define psouth 4
  92. #define peast 5
  93. #define pwest 6
  94. #define pexpand 9
  95. #define pwidth 10
  96. #define pheight 8
  97. #define pdec 13
  98. #define pinc 14
  99. #define pcircle 27
  100. #define poutl 16
  101. #define pincircle 20
  102.  
  103. #define igOK 1
  104. #define igCANCEL 10
  105. #define ighexpand 6
  106. #define igvexpand 14
  107. #define igwidth 7
  108. #define igheight 5
  109. #define ighdec 8
  110. #define ighinc 9
  111. #define igvdec 12
  112. #define igvinc 13
  113. #define igbox 27
  114. #define igoutl 2
  115. #define iginbox 14
  116.  
  117.  
  118. Rect prect;
  119.  
  120. /********************************************************************/
  121. pascal void drawview( dlog, itm)
  122.     DialogPtr dlog;
  123.     short itm;
  124. {
  125.  
  126.     frameit();
  127. }
  128.  
  129. frameit()
  130. {
  131.     Rect tr;
  132.     
  133.     tr = prect;
  134.     OffsetRect(&tr,hoffset,voffset);
  135.     
  136.     PenSize(3,3);
  137.     PenMode(patXor);
  138.     FrameRect(&tr);                    /* draw a box */
  139.  
  140.     PenMode(patCopy);
  141. }
  142.  
  143. /********************************************************************/
  144. pascal Boolean
  145. polardraw(td,tdevent,itemhit)
  146.     DialogPtr td;
  147.     EventRecord *tdevent;
  148.     short int *itemhit;
  149.     {
  150.     Point        where,newpt,anchorp;
  151.     int c;
  152.     
  153.     switch(tdevent->what) {
  154.         case keyDown:
  155.         case autoKey:
  156.             if ((c = (tdevent->message & charCodeMask)) == 13) {
  157.                 *itemhit = 1;
  158.                 return(true);            /* else let dialog handle it */
  159.             }
  160.             break;
  161.             
  162.         case mouseDown:
  163.             where = tdevent->where;                        /* anchor point */
  164.             where.h -= hoffset;                        /* position within frame */
  165.             where.v -= voffset;
  166.             
  167.             GlobalToLocal(&where);                        /* Get location */
  168.             if (where.h < 220 && where.v < 220) {
  169.                 if (where.h < 0) where.h = 0;
  170.                 if (where.v < 0) where.v = 0;
  171.                 if (where.h > 202) where.h = 202;            /* protect the range */
  172.                 if (where.v > 202) where.v = 202;
  173.                     
  174.                 frameit();                            /* un-draw a box */
  175.                 SetRect(&prect, where.h, where.v, where.h, where.v);
  176.                 anchorp = where;                            /* save anchor */
  177.                 while (StillDown()) {
  178.                     GetMouse(&newpt);
  179.                     newpt.h -= hoffset;
  180.                     newpt.v -= voffset;
  181.                     
  182.                     if (newpt.h < 0) newpt.h = 0;
  183.                     if (newpt.v < 0) newpt.v = 0;
  184.                     if (newpt.h > 202) newpt.h = 202;
  185.                     if (newpt.v > 202) newpt.v = 202;
  186.                     if (where != newpt) {    /* something changed */
  187.                         where = newpt;
  188.                         PenMode(patXor);
  189.                         frameit();                    /* un-draw a box */
  190.                         
  191.                         if (newpt.v <= anchorp.v) {            /* above, move bottom to anchor, top to point */
  192.                             prect.bottom = anchorp.v;
  193.                             prect.top = newpt.v;
  194.                         }
  195.                         else {                                /* below, move top to anchor, bottom to point */
  196.                             prect.top = anchorp.v;
  197.                             prect.bottom = newpt.v;
  198.                         }
  199.                         if (newpt.h <= anchorp.h) {            /* left, move right to anchor, left to point */
  200.                             prect.right = anchorp.h;
  201.                             prect.left = newpt.h;
  202.                         }
  203.                         else {
  204.                             prect.left = anchorp.h;
  205.                             prect.right = newpt.h;
  206.                         }
  207.                         
  208.                         frameit();                    /* draw a new box */
  209.                     }
  210.                 }
  211.                 *itemhit=pcircle;
  212.                 return(true);
  213.             }
  214.             break;
  215.         default:
  216.             break;
  217.     }
  218.     
  219.     *itemhit=0;
  220.     return(false);                
  221.  
  222. }
  223.  
  224. /********************************************************************/
  225. /*  polar attributes
  226. *   Display and work on the polar attributes dialog.
  227. */
  228. dopatt(tw)
  229.     struct Mwin *tw;
  230.     {
  231.     DialogPtr    theDialog;
  232.     short        itemType;
  233.     Handle        itemHdl;
  234.     Rect        itemRect,tr;
  235.     short        itemHit;
  236.     GrafPtr        savep;
  237.     int     i,denom,ashift,exx;
  238.     char  temp[40];
  239.     
  240.     GetPort(&savep);
  241.         
  242.     theDialog = GetNewDialog(pattDLOG, nil, (WindowPtr) -1);
  243.     
  244.     SetPort(theDialog);
  245.  
  246.     UItemAssign( theDialog, (short) pincircle, drawview);
  247.     UItemAssign( theDialog, (short) poutl, OutlineItem);
  248.  
  249.     tr = tw->dat->viewport;
  250.     denom = tw->dat->ydim;
  251.     
  252.     prect.top = 100 + 200*tr.top/denom;
  253.     prect.left = 100 + 200*tr.left/denom;
  254.     prect.right = 100 + 200*tr.right/denom;
  255.     prect.bottom = 100 + 200*tr.bottom/denom;
  256.         
  257.     exx = tw->dat->exx;
  258.     ashift = tw->dat->angleshift;
  259.     
  260.     GetDItem(theDialog, pexpand, &itemType, &itemHdl, &itemRect);
  261.     sprintf(temp,"%d",exx);
  262.     setitext(itemHdl, temp);
  263.  
  264.     do {
  265.         PenMode(patCopy);
  266.         GetDItem(theDialog, pnorth, &itemType, &itemHdl, &itemRect);    /* radio buttons */
  267.         SetCtlValue( (ControlHandle) itemHdl, ashift == 3 ? 1 : 0);
  268.         GetDItem(theDialog, psouth, &itemType, &itemHdl, &itemRect);
  269.         SetCtlValue( (ControlHandle) itemHdl, ashift == 1 ? 1 : 0);
  270.         GetDItem(theDialog, peast, &itemType, &itemHdl, &itemRect);
  271.         SetCtlValue( (ControlHandle) itemHdl, ashift == 0 ? 1 : 0);
  272.         GetDItem(theDialog, pwest, &itemType, &itemHdl, &itemRect);
  273.         SetCtlValue( (ControlHandle) itemHdl, ashift == 2 ? 1 : 0);
  274.         
  275.         i = (prect.right - prect.left)*denom/200*exx;
  276.         GetDItem(theDialog, pwidth, &itemType, &itemHdl, &itemRect);
  277.         sprintf(temp,"%d",i);
  278.         setitext(itemHdl, temp);
  279.         i = (prect.bottom - prect.top)*denom/200*exx;
  280.         GetDItem(theDialog, pheight, &itemType, &itemHdl, &itemRect);
  281.         sprintf(temp,"%d",i);
  282.         setitext(itemHdl, temp);
  283.  
  284.         ModalDialog(polardraw, &itemHit);
  285.         switch (itemHit) {
  286.         case pCANCEL:
  287.             DisposDialog(theDialog);
  288.             SetPort(savep);
  289.             return(0);
  290.         case pnorth:
  291.             ashift = 3;
  292.             break;
  293.         case peast:
  294.             ashift = 0;
  295.             break;
  296.         case pwest:
  297.             ashift = 2;
  298.             break;
  299.         case psouth:
  300.             ashift = 1;
  301.             break;
  302.         case pinc:
  303.             GetDItem(theDialog, pexpand, &itemType, &itemHdl, &itemRect);
  304.             sprintf(temp,"%d",++exx);
  305.             setitext(itemHdl, temp);
  306.             break;
  307.         case pdec:
  308.             if (exx <= 1) break;
  309.             GetDItem(theDialog, pexpand, &itemType, &itemHdl, &itemRect);
  310.             sprintf(temp,"%d",--exx);
  311.             setitext(itemHdl, temp);
  312.             break;
  313.         case pexpand:
  314.             GetDItem(theDialog, pexpand, &itemType, &itemHdl, &itemRect);
  315.             getitext(itemHdl, temp);
  316.             exx = max(1,atoi(temp));
  317.             sprintf(temp,"%d",exx);
  318.             setitext(itemHdl, temp);
  319.             break;            
  320.         case 1:
  321.             itemHit = pOK;
  322.             break;
  323.         default:
  324.             break;
  325.         }
  326.         
  327.     } while (itemHit != pOK);
  328.  
  329.     tw->dat->angleshift = ashift;
  330.     tw->dat->exx = tw->dat->exy = exx;
  331.     
  332.     DisposDialog(theDialog);
  333.     
  334.     tr.top = (prect.top - 100)*denom/200;
  335.     tr.left = (prect.left - 100)*denom/200;
  336.     tr.right = (prect.right - 100)*denom/200;
  337.     tr.bottom = (prect.bottom - 100)*denom/200;
  338.     tw->dat->viewport = tr;
  339.     
  340.     SetPort(savep);
  341. }
  342.  
  343. /********************************************************************/
  344. /*  Image size attributes
  345. *   Display and work on the image size dialog.
  346. */
  347. dosize(tw)
  348.     struct Mwin *tw;
  349.     {
  350.     DialogPtr    theDialog;
  351.     short        itemType;
  352.     Handle        itemHdl;
  353.     Rect        itemRect;
  354.     short        itemHit;
  355.     GrafPtr        savep;
  356.     int     exx,exy,xbig,ybig;
  357.     char  temp[40];
  358.     
  359.     GetPort(&savep);
  360.         
  361.     theDialog = GetNewDialog(isizeDLOG, nil, (WindowPtr) -1);
  362.     
  363.     SetPort(theDialog);
  364.  
  365.     UItemAssign( theDialog, (short) igoutl, OutlineItem);
  366.  
  367.     xbig = tw->dat->xsize;
  368.     ybig = tw->dat->ysize;
  369.         
  370.     exx = tw->dat->exx;
  371.     exy = tw->dat->exy;
  372.     
  373.     GetDItem(theDialog, igwidth, &itemType, &itemHdl, &itemRect);
  374.     sprintf(temp,"%d",xbig);
  375.     setitext(itemHdl, temp);
  376.     GetDItem(theDialog, igheight, &itemType, &itemHdl, &itemRect);
  377.     sprintf(temp,"%d",ybig);
  378.     setitext(itemHdl, temp);
  379.     GetDItem(theDialog, ighexpand, &itemType, &itemHdl, &itemRect);
  380.     sprintf(temp,"%d",exx);
  381.     setitext(itemHdl, temp);
  382.     GetDItem(theDialog, igvexpand, &itemType, &itemHdl, &itemRect);
  383.     sprintf(temp,"%d",exy);
  384.     setitext(itemHdl, temp);
  385.  
  386.     do {
  387.         PenMode(patCopy);
  388.         
  389.         ModalDialog(nil, &itemHit);
  390.         
  391.         switch (itemHit) {
  392.         case igCANCEL:
  393.             DisposDialog(theDialog);
  394.             SetPort(savep);
  395.             return(0);
  396.         case ighinc:
  397.             GetDItem(theDialog, ighexpand, &itemType, &itemHdl, &itemRect);
  398.             sprintf(temp,"%d",++exx);
  399.             setitext(itemHdl, temp);
  400.             break;
  401.         case ighdec:
  402.             if (exx <= 1) break;
  403.             GetDItem(theDialog, ighexpand, &itemType, &itemHdl, &itemRect);
  404.             sprintf(temp,"%d",--exx);
  405.             setitext(itemHdl, temp);
  406.             break;
  407.         case ighexpand:
  408.             GetDItem(theDialog, ighexpand, &itemType, &itemHdl, &itemRect);
  409.             getitext(itemHdl, temp);
  410.             exx = max(1,atoi(temp));
  411.             break;            
  412.         case igvinc:
  413.             GetDItem(theDialog, igvexpand, &itemType, &itemHdl, &itemRect);
  414.             sprintf(temp,"%d",++exy);
  415.             setitext(itemHdl, temp);
  416.             break;
  417.         case igvdec:
  418.             if (exy <= 1) break;
  419.             GetDItem(theDialog, igvexpand, &itemType, &itemHdl, &itemRect);
  420.             sprintf(temp,"%d",--exy);
  421.             setitext(itemHdl, temp);
  422.             break;
  423.         case igvexpand:
  424.             GetDItem(theDialog, igvexpand, &itemType, &itemHdl, &itemRect);
  425.             getitext(itemHdl, temp);
  426.             exy = max(1,atoi(temp));
  427.             break;            
  428.         case igwidth:
  429.             GetDItem(theDialog, igwidth, &itemType, &itemHdl, &itemRect);
  430.             getitext(itemHdl, temp);
  431.             xbig = max(tw->dat->xdim,atoi(temp));
  432.             exx = xbig / tw->dat->xdim;
  433.             GetDItem(theDialog, ighexpand, &itemType, &itemHdl, &itemRect);
  434.             sprintf(temp,"%d",exx);
  435.             setitext(itemHdl, temp);
  436.             break;
  437.         case igheight:
  438.             GetDItem(theDialog, igheight, &itemType, &itemHdl, &itemRect);
  439.             getitext(itemHdl, temp);
  440.             ybig = max(tw->dat->ydim,atoi(temp));
  441.             exy = ybig / tw->dat->ydim;
  442.             GetDItem(theDialog, igvexpand, &itemType, &itemHdl, &itemRect);
  443.             sprintf(temp,"%d",exy);
  444.             setitext(itemHdl, temp);
  445.             break;
  446.         case 1:
  447.             itemHit = igOK;
  448.             break;
  449.         default:
  450.             break;
  451.         }
  452.  
  453. /*
  454. *  adjust dependent fields, depending on what was hit.
  455. */
  456.         switch (itemHit) {
  457.         case ighexpand:
  458.         case ighdec:
  459.         case ighinc:
  460.             xbig = exx * tw->dat->xdim;
  461.             GetDItem(theDialog, igwidth, &itemType, &itemHdl, &itemRect);
  462.             sprintf(temp,"%d",xbig);
  463.             setitext(itemHdl, temp);
  464.             GetDItem(theDialog, ighexpand, &itemType, &itemHdl, &itemRect);
  465.             sprintf(temp,"%d",exx);
  466.             setitext(itemHdl, temp);
  467.             break;
  468.         case igvexpand:
  469.         case igvdec:
  470.         case igvinc:
  471.             ybig = exy * tw->dat->ydim;
  472.             GetDItem(theDialog, igheight, &itemType, &itemHdl, &itemRect);
  473.             sprintf(temp,"%d",ybig);
  474.             setitext(itemHdl, temp);
  475.             GetDItem(theDialog, igvexpand, &itemType, &itemHdl, &itemRect);
  476.             sprintf(temp,"%d",exy);
  477.             setitext(itemHdl, temp);
  478.             break;
  479.         }
  480.         
  481.     } while (itemHit != igOK);
  482.  
  483.     tw->dat->exx = exx;
  484.     tw->dat->exy = exy;
  485.     tw->dat->xsize = xbig;
  486.     tw->dat->ysize = ybig;
  487.     
  488.     DisposDialog(theDialog);
  489.         
  490.     SetPort(savep);
  491. }
  492. /*
  493.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  494.     openingdialog        Show and remove the openingdialog
  495.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  496. */
  497. DialogPtr    openDialog;
  498. openingdialog(mode)
  499.     int            mode;
  500. {
  501.     pascal void VersionNumber();
  502.  
  503.     if (mode) 
  504.         {
  505.         Rect        ibox;
  506.         char        **ihndl;
  507.         short        typ;
  508.         openDialog = GetNewDialog(openDLOG, nil, (WindowPtr) -1);
  509.  
  510.         GetDItem(openDialog, 3, &typ, &ihndl, &ibox);
  511.         setitext(ihndl, VERSION);
  512.         DrawDialog(openDialog);
  513.     }
  514.     else
  515.         DisposDialog(openDialog);
  516.  
  517.     return;
  518. }
  519. /*
  520.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  521.     showAboutMeDialog        standard about dialog processing
  522.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  523. */
  524. showAboutMeDialog()
  525. {
  526.     DialogPtr    theDialog;
  527.     GrafPtr        savePort;
  528.     short        itemHit;
  529.     pascal void VersionNumber(),
  530.                 OutlineItem();
  531.     extern char netfailed;
  532.     Boolean        done = false;
  533.     
  534.     if (netfailed)
  535.         paramtext("Network Disabled","","","");
  536.     else
  537.         paramtext("Network Enabled","","","");
  538.  
  539.     GetPort(&savePort);
  540.     theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
  541.     SetPort(theDialog);
  542.     UItemAssign(theDialog,(short)(aboutOK), OutlineItem);
  543.     UItemAssign(theDialog,(short) 3, VersionNumber);
  544.  
  545.     do
  546.     {
  547.         ModalDialog(NULL, &itemHit);
  548.            if        (itemHit == aboutOK)
  549.                        {DisposDialog(theDialog);
  550.                      done = true;
  551.                     }
  552.            else if    (itemHit == aboutHELP)
  553.                        {DisposDialog(theDialog);
  554.                      done = true;
  555.                      ShowHelp();
  556.                     }
  557.            else;
  558.     }
  559.     while (done == false);
  560.     
  561.     SetPort(savePort);
  562.     return;
  563. }
  564. /*
  565.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  566.     ShowHelp        Access the Help Compiler routine which
  567.                     displays the on-line help.
  568.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  569. */
  570. #include "resources.h"
  571.  
  572. ShowHelp()
  573. {
  574.     Handle    rsrcH;
  575.     ProcPtr pp;
  576.  
  577.     if (rsrcH = GetResource('HCOD', 2000))
  578.     {
  579.         HLock(rsrcH);
  580.         pp = (ProcPtr) *rsrcH;
  581.         (*pp)();
  582.         HUnlock(rsrcH);
  583.         ReleaseResource(rsrcH);
  584.     }
  585. }
  586. /*
  587.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  588.     VersionNumber        Prints a version number string into a
  589.                         dialog box.  Requires an item number
  590.                         to be present to define where to
  591.                         center the string.
  592.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  593. */
  594. pascal void VersionNumber( theDialog, theItem)
  595.     DialogPtr    theDialog;
  596.     short        theItem;
  597. {
  598.     Rect        ibox;
  599.     char        **ihndl;
  600.     short        typ;
  601.  
  602.     GetDItem( theDialog, (int)(theItem), &typ, &ihndl, &ibox);
  603.     TextFont( 3);
  604.     TextSize( 9);
  605.     MoveTo( ibox.left                     +
  606.             ((ibox.right-ibox.left) / 2) -
  607.             (stringwidth( VERSION)/2),
  608.             ibox.bottom-2);
  609.     drawstring( VERSION );
  610. }
  611. /*
  612.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  613.     UItemAssign
  614.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  615. */
  616. UItemAssign( dlog, item, proc)
  617.     DialogPtr    dlog;
  618.     short            item;
  619.     int            (*proc)();
  620. {
  621.     Rect        ibox;
  622.     char        **ihndl;
  623.     short        typ;
  624.  
  625.     GetDItem( dlog, item, &typ, &ihndl, &ibox);
  626.     SetDItem( dlog, item,  typ,  (Handle) proc, &ibox);
  627. }
  628.  
  629. /***************************************************************************/
  630. /*  checksave
  631. *   See if the window which is about to go away really should be saved first.
  632. */
  633. checksave(tw)
  634.     struct Mwin *tw;
  635.     {
  636.     DialogPtr    theDialog;
  637.     short itemHit;
  638.  
  639.     if (!tw->dat->needsave)
  640.         return(0);
  641.     
  642.     if (!tw->dat->fname[0])
  643.         paramtext(tw->dat->dvar,"","","");
  644.     else
  645.         paramtext(tw->dat->fname,"","","");
  646.  
  647.     theDialog = GetNewDialog(134, nil, (WindowPtr) -1);
  648.     
  649.     UItemAssign( theDialog, 4, OutlineItem );
  650.     do {
  651.         ModalDialog(nil, &itemHit);
  652.     } while (itemHit < 1 || itemHit > 5);
  653.  
  654.     DisposDialog(theDialog);
  655.     
  656.     if (itemHit == 1) {                    /* go for the save */
  657.         if (saveit(tw))
  658.             return(-1);
  659.     }
  660.     else if (itemHit == 5)
  661.         return(-1);                        /* Cancel return */
  662.  
  663.     return(0);
  664. }
  665.  
  666.  
  667. /***************************************************************************/
  668. /*  findfunction
  669. *   Work with the user to find an external function which may be in another
  670. *   file.  Returns 0 if another attempt should be made, -1 if the user gave up.
  671. */
  672.  
  673. extern char netfailed;
  674.  
  675. findfunction(s)
  676.     char *s;
  677. {
  678.     DialogPtr    theDialog;
  679.     short        itemType;
  680.     Handle        itemHdl;
  681.     Rect        itemRect;
  682.     short itemHit;
  683.  
  684.     paramtext(s,"","","");
  685.  
  686.     SetCursor(&qd.arrow);
  687.  
  688.     theDialog = GetNewDialog(137, nil, (WindowPtr) -1);
  689.     
  690.     UItemAssign( theDialog, 3, OutlineItem );
  691.     
  692.     if (netfailed) {            /* no networking, don't allow this option */
  693.         GetDItem(theDialog, 8, &itemType, &itemHdl, &itemRect);
  694.         HiliteControl((ControlHandle)itemHdl,255);
  695.     }
  696.     
  697.     do {
  698.         ModalDialog(nil, &itemHit);
  699.     } while (itemHit != 1 && itemHit != 2 && itemHit != 8);
  700.  
  701.     DisposDialog(theDialog);
  702.     
  703.     if (itemHit == 1) {                    /* go for the function file */
  704.          SFReply reply;
  705.          SFTypeList tlst;
  706.          Point wh;
  707.          int ret;
  708.     
  709.         wh.h = wh.v = 50;
  710.         tlst[0] = 'DSff';
  711.         sfgetfile(&wh, "Open External Function Library", nil, 1, tlst, nil, &reply);
  712.         if (reply.good) {
  713.             p2cstr(reply.fName);
  714.             setvol(NULL, reply.vRefNum);            /* set to this volume (dir) */
  715.             ret = openresfile(reply.fName);            /* Open its resource fork */
  716.             if (ret < 0)
  717.                 return(-1);
  718.             else
  719.                 return(0);
  720.         }
  721.         else
  722.             return(-1);                    /* user cancel */
  723.     }
  724.     else if (itemHit == 8) {
  725.         return(1);                        /* wants network function */
  726.     }
  727.     
  728.     
  729.     return(-1);                            /* Cancel return - back to notebook */
  730.  
  731. }
  732.  
  733. /************************************************************************/
  734. /*  remote execution setup.
  735. *   We need to get all of the fields required by rexec because we use
  736. *   the rexec protocol to get going.  
  737. *
  738. *    passwords are not echoed to the screen.
  739. *
  740. */
  741.  
  742. char *exuser=NULL,                        /* user name */
  743.     *expass=NULL,                        /* password */
  744.     *exmachine=NULL;                    /* host name */
  745.  
  746. int 
  747.     exconnect=512;                        /* compute port # is rexec */
  748.     
  749. pascal Boolean pfilt();                    /* non-echoing modal dialog processor for password */
  750.  
  751. exremote(fnp)
  752.     char *fnp;
  753.     {
  754.     char s[256];
  755.     DialogPtr    theDialog;
  756.     short        itemType;
  757.     Handle        itemHdl;
  758.     Rect        itemRect;
  759.     short itemHit,i;
  760.  
  761.     
  762.     if (exuser == NULL) {
  763.         exuser = (char *)NewPtr(256);
  764.         exuser[0] = 0;
  765.     }
  766.     if (exmachine == NULL) {
  767.         exmachine = (char *)NewPtr(256);
  768.         exmachine[0] = 0;
  769.     }
  770.     if (expass == NULL) {
  771.         expass = (char *)NewPtr(256);
  772.         expass[0] = 0;
  773.     }
  774.     
  775.     if (!exuser || !exmachine || !expass)
  776.         return(-1);
  777.         
  778.     paramtext(fnp,"","","");
  779.  
  780.     SetCursor(&qd.arrow);
  781.  
  782.     theDialog = GetNewDialog(138, nil, (WindowPtr) -1);
  783.     
  784.     GetDItem(theDialog, 6, &itemType, &itemHdl, &itemRect);
  785.     for (i=0; i< strlen(expass); i++)        /* echo Δ instead of chars */
  786.         s[i] = 'Δ';
  787.     s[i] = 0;
  788.     setitext(itemHdl, s);
  789.     GetDItem(theDialog, 5, &itemType, &itemHdl, &itemRect);
  790.     setitext(itemHdl, exuser);
  791.     GetDItem(theDialog, 4, &itemType, &itemHdl, &itemRect);
  792.     setitext(itemHdl, exmachine);
  793.     SelIText(theDialog, 4, 0,32767);
  794.  
  795.     UItemAssign( theDialog, 3, OutlineItem );
  796.     do {
  797.         ModalDialog(pfilt, &itemHit);
  798.     } while (itemHit < 1 || itemHit > 2);
  799.  
  800.     if (itemHit == 1) {
  801.         GetDItem(theDialog, 5, &itemType, &itemHdl, &itemRect);
  802.         getitext(itemHdl, exuser);
  803.         GetDItem(theDialog, 4, &itemType, &itemHdl, &itemRect);
  804.         getitext(itemHdl, exmachine);
  805.     }
  806.     
  807.     DisposDialog(theDialog);
  808.     
  809.     if (itemHit != 1)
  810.         return(-1);
  811.  
  812.     return(0);
  813. }
  814.  
  815. /*****************************************************************/
  816. /*   Modalproc for prompting which is tied to exremote()
  817. *    This proc makes sure that key echoes are suppressed for item #6
  818. */
  819.  
  820. pascal Boolean
  821. pfilt(td,tdevent,itemhit)
  822.     DialogPtr td;
  823.     EventRecord *tdevent;
  824.     short int *itemhit;
  825.     {
  826.     short        itemType;
  827.     Handle        itemHdl;
  828.     Rect        itemRect;
  829.     TEHandle    te;
  830.     char s[256];
  831.     int c,i,len,ret;
  832.     
  833.     if (tdevent->what != keyDown && tdevent->what != autoKey)
  834.         return(false);
  835.  
  836.     switch(tdevent->what) {
  837.         case keyDown:
  838.         case autoKey:
  839.             len = strlen(expass);
  840. /*
  841. *  If it is CR, take it as OK button, as per Inside Mac
  842. */
  843.             if ((c = (tdevent->message & charCodeMask)) == 13) {
  844.                 *itemhit = 1;
  845.                 return(true);
  846.             }
  847.             
  848.             if (*itemhit != 6)                /* limit my actions to item #6 */
  849.                 return(false);
  850. /*
  851. *  If it is tab, pass it through to modaldialog untouched
  852. */
  853.             if (c == 9)
  854.                 return(false);
  855. #ifdef DONTWORK
  856. /*
  857. *  Check selection start and delete password if not at end
  858. */
  859.             if ((*te)->selStart < len) {
  860.                 *expass = '\0';
  861.                 len = 0;
  862.                 ret = false;
  863.             }
  864. #endif                
  865. /*
  866. *  If an ASCII char, take it as part of password and echo Δ
  867. */
  868.             if (c > 31) {
  869.                 if (len < 16) {
  870.                     expass[len] = c;
  871.                     expass[++len] = '\0';
  872.                 }
  873.                 ret = true;
  874.             }
  875.             
  876.  
  877.             else {        /* anything else is illegal, terminate string */
  878.                 *expass = '\0';
  879.                 len = 0;
  880.                 ret = false;
  881.             }
  882.                             
  883.                 
  884. /*
  885. *  Clean up after myself, set the Δ echo to the right length.
  886. */
  887.             GetDItem(td, *itemhit, &itemType, &itemHdl, &itemRect);
  888.             for (i=0; i< len; i++)
  889.                 s[i] = 'Δ';
  890.             s[len] = 0;
  891.             setitext(itemHdl, s);
  892.             SelIText(td, *itemhit, 32767, 32767);
  893.             return(ret);
  894.             
  895.             break;
  896.             
  897.  
  898.         default:
  899.             break;
  900.     }
  901.  
  902.     return(false);                /* default return, unknown key or mouse pressed */        
  903.  
  904. }
  905.  
  906. /************************************************************************/
  907. /*  ncstrcmp
  908. *   No case string compare.
  909. *   Only returns 0=match, 1=no match, does not compare greater or less
  910. *   There is a tiny bit of overlap with the | 32 trick, but shouldn't be
  911. *   a problem.  It causes some different symbols to match.
  912. */
  913. ncstrcmp(sa,sb)
  914.     char *sa,*sb;
  915.     {
  916.  
  917.     while (*sa && *sa < 33)        /* don't compare leading spaces */
  918.         sa++;
  919.     while (*sb && *sb < 33)
  920.         sb++;
  921.  
  922.     while (*sa && *sb) {
  923.         if ((*sa != *sb) && ((*sa | 32) != (*sb | 32)))
  924.             return(1);
  925.         sa++;sb++;
  926.     }
  927.     if (!*sa && !*sb)        /* if both at end of string */
  928.         return(0);
  929.     else
  930.         return(1);
  931. }
  932.  
  933. /***************************************************************************/
  934. max(i,j)
  935.     int i,j;
  936. {
  937.     if (i < j)
  938.         return(j);
  939.     else
  940.         return(i);
  941. }
  942.  
  943. /***************************************************************************/
  944. /*  askvar
  945. *   Ask the user if he spelled the name right.
  946. *   Returns 1 on a valid selection (OK), 0 if the user hits CANCEL.
  947. *   The parameter s must contain 255 characters of space for the textedit string.
  948. */
  949. askvar(s)
  950.     char *s;
  951.     {
  952.     DialogPtr    theDialog;
  953.     short        itemType;
  954.     Handle        itemHdl;
  955.     Rect        itemRect;
  956.     short        itemHit;
  957.  
  958.     theDialog = GetNewDialog(136, nil, (WindowPtr) -1);
  959.     
  960.     SetCursor(&qd.arrow);
  961.  
  962.     UItemAssign( theDialog, 5, OutlineItem );
  963.     GetDItem(theDialog, 4, &itemType, &itemHdl, &itemRect);
  964.     setitext(itemHdl, s);
  965.     SelIText(theDialog, 4, 0,32767);
  966.     
  967.     do {
  968.         ModalDialog(nil, &itemHit);
  969.         if (itemHit == 2) {                    /* Cancel, don't care about return */
  970.             DisposDialog(theDialog);
  971.             return(0);
  972.         }
  973.     } while (itemHit < 1 || itemHit > 2);
  974.  
  975.     GetDItem(theDialog, 4, &itemType, &itemHdl, &itemRect);
  976.     getitext(itemHdl, s);
  977.  
  978.     DisposDialog(theDialog);
  979.     
  980.     return(1);
  981. }
  982.  
  983. /********************************************************************/
  984. /*  netalert
  985. *  Inform the user of a network problem.
  986. */
  987. netalert(s)
  988.     char *s;
  989. {
  990.     char *p;
  991.     
  992.     p = s;
  993.     
  994.     while (*p) {
  995.         if (*p < 32)
  996.             *p = 13;                    /* returns are mostly harmless */
  997.         p++;
  998.     }
  999.             
  1000.     SetCursor(&qd.arrow);
  1001.     
  1002.     paramtext(s,"","","");
  1003.     
  1004.     StopAlert(1008, nil);
  1005.     
  1006.     return;
  1007. }
  1008.